﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DaoHam
{
    public class DonThuc : BieuThuc
    {
        private float a;
        private float n;

        protected DonThuc(float _a, float _n)
        {
            a = _a;
            n = _n;
        }

        static public BieuThuc TaoDonThuc(float _a, float _n)
        {
            if(_a == 0 || _n == 0)
            {
                return HangSo.TaoHangSo(_a);
            }
            return new DonThuc(_a, _n);
        }

        public override float TinhBieuThuc(float x)
        {
            return (float)(a*Math.Pow((double)x, (double)n));
        }

        public override BieuThuc TinhDaoHam()
        {
            return new DonThuc(a * n, n - 1);
        }

        public override string XuatBieuThuc()
        {
            string a1 = "";
            string n1 = "";
            if (a != 1)
            {
                a1 = a.ToString();
            }
            if(n != 1)
            {
                n1 = "^" + n.ToString();
            }
            return a1 + "x" + n1;
        }

        public override string ToString(Convert cv)
        {
            return XuatBieuThuc();
        }
    }
}
